﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>




<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>IMES</title>
</head>
<body>
    <div class="layui-panel">
        <div style="padding: 32px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="font-weight: bold;float: left;">销售订单</label>
                    <div style="margin-left: 600px;">
                        <input type="text" placeholder="订单编号" id="orderId" style="line-height:25px;">
                        <button class="layui-btn layui-bg-blue" onclick="get()" style="height:29px;line-height:14px">查询</button>
                        <button class="layui-btn" lay-on="test-page-custom" style="height:29px;line-height:14px">新建</button>
                        <button class="layui-btn layui-bg-blue" style="height:29px;line-height:14px" lay-event="edit">编辑</button>
                        <button class="layui-btn layui-bg-red" style="height:29px;line-height:14px" lay-event="delete">删除</button>
                        <button class="layui-btn layui-bg-red" style="height:29px;line-height:14px" onclick="print()">打印</button>
                        <button class="layui-btn layui-bg-red" style="height:29px;line-height:14px" lay-on="test-page-approval" ">审核</button>
                        <button class="layui-btn layui-btn-primary layui-border-green" style="height:29px;line-height:14px" lay-event="enable">导出</button>
                    </div>
                </div>
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th>
                                <input type="checkbox" name="check">
                            </th>
                            <th>单据编号</th>
                            <th>备注</th>
                            <th>创建日期</th>
                            <th>创建人</th>
                            <th>修改人</th>
                            <th>修改时间</th>
                        </tr>
                    </thead>
                    <tbody id="body">
                    </tbody>
                </table>
            </div>
        </div>
        <div class="layui-panel" style="margin-top: 20px;">
            <div style="padding: 32px;"></div>
        </div>
    </div>

    <script>
        $(function () {
            getList();
        })
        //销售订单列表显示
        function getList() {
            $.ajax({
                url: '@ViewBag.Darius'+"/api/Orders/SearchOrder",
                type: "post",
                data: JSON.stringify({
                    orderNo: $("#orderNo").val() || "",
                }),
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    console.log(res)
                    $(res.data).each(function (item) {
                        $("#body").append(`<tr>

                                              <td>
                                                <input type="checkbox" value="${this.orderId}" name="check"></input>
                                              </td>
                                              <td>${this.orderNo}</td>
                                              <td>${this.orderNotes}</td>
                                              <td>${this.createDate.split("T")[0]}</td>
                                              <td>${this.createName}</td>
                                              <td>${this.updateName}</td>
                                              <td>${this.updateDate}</td>
                                          </tr>`
                         )
                    })
                }
            })
        }



    </script>
</body>
</html>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="//unpkg.com/layui@2.9.20/dist/layui.js"></script>
<script>

    layui.use(function () {
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        // 事件
        util.on('lay-on', {
            'test-page-custom': function () {
                layer.open({
                    type: 2,
                    area: ['1300px', '750px'],
                    shadeClose: true,
                    title: '销售订单（新建）',
                    content: '/Orders/OrderAddView',

                });
            }
        });

        util.on('lay-on', {
            'test-page-approval': function () {
                layer.open({
                    type: 2,
                    area: ['1300px', '750px'],
                    shadeClose: true,
                    title: '审核',
                    content: '/Orders/OrderApprovalView',

                });
            }
        });

        //导出
        util.on(
            'lay-event', {
            'enable': function () {
                layer.confirm('确认要导出吗？', {
                    btn: ['确认', '取消'] //按钮
                }, function () {
                    window.location.href = '@ViewBag.Darius'+"/api/Orders/OrderImport";
                    //点击确认关闭弹框
                    layer.closeAll();
                }, function () {
                    layer.msg('已取消');
                });
            }
        });

        //删除
        util.on('lay-event', {
            'delete': function () {
                var ids = $(":checkbox:gt(0):checked").map(function () {
                    return $(this).val();
                }).get().join(",");
                console.log(ids)
                if (ids.length == 0) {
                    layer.msg("请选择要删除的订单！");
                    return;
                }
                debugger;
                layer.confirm('确认要删除吗？', {
                    btn: ['确认', '取消'] //按钮
                }, function () {
                    $.ajax({
                        url: '@ViewBag.Darius' + "/api/Orders/DeleteOrder",
                        type: "put",
                        data: JSON.stringify({
                            saleOrderIds:ids
                        }),
                        dataType: "json",
                        contentType: "application/json",
                        success: function (res) {
                            if (res.code >0) {
                                layer.msg("删除成功！");
                                //刷新页面
                                location.reload();
                            } else {
                                layer.msg("删除失败！");
                            }
                        }
                    })
                });
            }
        });

        //编辑跳出弹出框
        util.on('lay-event', {
            'edit': function () {
                var ids = $(":checkbox:gt(0):checked").map(function () {
                    return $(this).val();
                }).get().join(",");
                if (ids.length == 0) {
                    layer.msg("请选择要编辑的订单！");
                    return;
                }
                if (ids.split(",").length > 1) {
                    layer.msg("只能选择一行进行编辑！");
                    return;
                }
                layer.open({
                    type: 2,
                    area: ['1300px', '750px'],
                    shadeClose: true,
                    title: '销售订单（编辑）',
                    content: '/Orders/OrderGetView?orderId=' + ids,
                });
            }
        });



    });


</script>
<script>

    //打印
    function print() {
        var ids = $(":checkbox:gt(0):checked").map(function () {
            return $(this).val();
        }).get().join(",");
        if (ids.length == 0) {
            layer.msg("请选择要打印的订单！");
            return;
        }
        if (ids.split(",").length > 1) {
            layer.msg("只能选择一行进行打印！");
            return;
        }
        window.open("/Orders/HiprintView?id=" + ids);
    }
</script>


